#ifndef RSS_H_INCLUDED
#define RSS_H_INCLUDED

#ifdef __cplusplus
extern "C"
{
#endif

#include "ini.h"
#include "common.h"

//------------------------------------------------------------------------------
// defines
//------------------------------------------------------------------------------

#define STATISTICS_FILE_NAME    "statistics.txt"

//------------------------------------------------------------------------------
// enums
//------------------------------------------------------------------------------

enum
{
    RSS_SIZE = 1024,
    RSS_SIZE_HALF = RSS_SIZE / 2,
    DAY_OF_MONTH_FOR_SENDING_STATISTICS_LOG = 1
};

//------------------------------------------------------------------------------
// typedefs
//------------------------------------------------------------------------------

/**
 * @struct item_t
 *         This struct provides all the items of an RSS source.
 */
typedef struct item
{
    char    title[RSS_SIZE_HALF];
    char*   url;
    char*   pubdate;
    char    description[RSS_SIZE];
    char*   img_url;
} item_t;

/**
 * @struct feed_t
 *         This struct provides all the data related with an RSS feed.
 */
typedef struct feed
{
    char*   title;
    char*   pubdate;
    char*   language;
    int     itemcount;  ///< Number of items found in the items array
    item_t* items;      ///< Items array
} feed_t;

/**
 * @struct exp_keyword_t
 *         This struct provides data for keywords with boolean expression.
 */
typedef struct complex_keyword
{
    char*   key;
    char    sign;
} complex_keyword_t;

//------------------------------------------------------------------------------
// functions
//------------------------------------------------------------------------------

bool
RSS_Init(const char** a_feed_sources, 
         int a_feed_count, 
         customer_t* a_customers, 
         int a_customer_count);

bool
RSS_DownloadFeeds();

void
RSS_SortFeedsbyDate();

const feed_t*
RSS_GetFeeds();

bool
RSS_CreateDigests();

bool
RSS_TextFormatDigest(int a_customer);

bool
RSS_HTMLFormatDigest(int a_customer);

bool
RSS_LoadFeed(const char* a_file);

void
RSS_Free();

void
RSS_LogStatistics();

/**
 * @return A dynamically allocated string containing the path
 *
 * @warning The caller must call free() to release the allocated memory
 */
char *
RSS_GetStatisticsFilePath();

#ifdef __cplusplus
}
#endif

#endif // RSS_H_INCLUDED
